package org.graduation.common;

import lombok.extern.slf4j.Slf4j;
import org.graduation.model.common.ResponseResult;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
public class ExceptionCatch {

    @ExceptionHandler(Exception.class)
    public ResponseResult exception(Exception e) {
        e.fillInStackTrace();
        log.warn("catch exception: " + e.getMessage());
        return ResponseResult.failed();
    }

    @ExceptionHandler(ServiceException.class)
    public ResponseResult serviceException(ServiceException e) {
        e.fillInStackTrace();
        log.warn("catch exception: " + e.getMessage());
        return ResponseResult.failed();
    }

    @ExceptionHandler(NoPermissionException.class)
    public ResponseResult NoPermissionException(NoPermissionException e) {
        log.warn("catch exception: " + e.getMessage());
        return ResponseResult.failed(e.getMessage());
    }
}
